package com.itheima.action;



import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.itheima.utils.BaseAction;

import cn.itcast.crm.domain.Customer;
import itcast.bos.domain.base.Area;
import itcast.bos.domain.finaldemo.FinalDemo;
import itcast.bos.domain.orders.Order;

@Controller
@ParentPackage("json-default")
@Namespace("/")
@Scope("prototype")
public class OrderAction extends BaseAction<Order> {
	
	private String recAreaInfo;
	private String sendAreaInfo;
	
	
	@Action(value="addOrder",results={@Result(name="success",type="redirect",location="./index.html")})
	public String addOrder() {
		//System.out.println("订单详情-------------"+model);
		System.out.println("recAreaInfo------------"+recAreaInfo);
		System.out.println("sendAreaInfo------------"+sendAreaInfo);
		//先把数据封装上去     sendArea recArea  Custom.id
		Area sendArea=new Area();
		String[] sends = sendAreaInfo.split("/");
		sendArea.setProvince(sends[0]);
		sendArea.setCity(sends[1]);
		sendArea.setDistrict(sends[2]);
		Area recArea=new Area();
		String[] recs = recAreaInfo.split("/");
		recArea.setProvince(recs[0]);
		recArea.setCity(recs[1]);
		recArea.setDistrict(recs[2]);
		Customer customer=(Customer) ServletActionContext.getRequest().getSession().getAttribute("customer");
		//赋值
		model.setSendArea(sendArea);
		model.setRecArea(recArea);
		System.out.println("model----------------"+model);
		model.setCustomer_id(customer.getId());
		System.out.println("订单详情-------------"+model);
		//添加订单
		WebClient.create(FinalDemo.Bos_Url+"/bos_management/services/orderService/addOrder").post(model);
		
		return SUCCESS;
	}


	public String getRecAreaInfo() {
		return recAreaInfo;
	}


	public void setRecAreaInfo(String recAreaInfo) {
		this.recAreaInfo = recAreaInfo;
	}


	public String getSendAreaInfo() {
		return sendAreaInfo;
	}


	public void setSendAreaInfo(String sendAreaInfo) {
		this.sendAreaInfo = sendAreaInfo;
	}
	
}
